package com.sanyue.thread;

import org.junit.Test;
import sun.tools.jconsole.Worker;

import static sun.jvm.hotspot.runtime.PerfMemory.start;

/**
 * @author sanyue
 * @version 1.0
 * @description: TODO
 * @date 2022/3/3 下午9:28
 */
public class ThreadABC extends Thread{
    private int num;
    private static final Object LOCK = new Object();

    @Override
    public void run() {
        super.run();
    }

    private void printABC(String name, int targetNum) {
        for (int i = 0; i < 10; i++) {
            synchronized (LOCK) {
                while (num % 3 != targetNum) {
                    try {
                        LOCK.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                num++;
                System.out.println(Thread.currentThread().getName()+":"+name);
                LOCK.notifyAll();
            }
        }
    }




    public static void main(String[] args) {
        ThreadABC threadABC = new ThreadABC();
        new Thread(() -> {
            threadABC.printABC("A", 0);
        }, "A1").start();
        new Thread(() -> {
            threadABC.printABC("B", 1);
        }, "B1").start();
        new Thread(() -> {
            threadABC.printABC("C", 2);
        }, "C1").start();
    }
}

